import React, { Component } from 'react'
import {
	Text, View, TouchableOpacity, Image
} from "react-native";
import { styles } from '../../_common/style';
import { StateLightBox } from '../../../../../component/Store';
import OrderApproveService from '../../_common/service';
import { GLOBAL } from '../../../../../config/global';
import { ProgressModal } from '../../../../../components/common/ProgressModal';
const scale = GLOBAL.SCALE;
//审批状态
export class StateSection extends Component {
	constructor(props) {
		super(props);
		this.state = {
			loaded: false
		}

		this._closeLightBox = this._closeLightBox.bind(this);

		this.stateLightBoxData = {
			onClosePress: this._closeLightBox,
			modalVisible: false,
			title: '',
			rowDataList: [],
		};
	}

	_closeLightBox () {
		this.stateLightBoxData.modalVisible = false;
		const { stateLightBoxVisible } = this.state;
		this.setState({
			stateLightBoxVisible: !stateLightBoxVisible,
		});
	}

	//审批节点
	async	_didPressShowStateLightBox (orderId, processInstanceId) {

		let { corpId } = this.props;

		this.setState({
			loaded: true
		});

		//查询审批节点
		let stateInfo = await OrderApproveService.getApproveState({ approveType: this.props.approveType }, { bizId: orderId, processInstanceId,corpId });

		this.setState({
			loaded: false
		});

		this.stateLightBoxData.modalVisible = true;
		this.stateLightBoxData.title = '审批状态';
		this.stateLightBoxData.rowDataList = stateInfo.map((item, index) => {
			return {
				taskName: item.taskName,
				auditTime: item.auditTime,
				auditResult: item.auditResult,
				remark: item.remark,
				logId: item.logId,
				auditStaffName: item.auditStaffName
			};
		})

		const { stateLightBoxVisible } = this.state;
		this.setState({
			stateLightBoxVisible: !stateLightBoxVisible
		});
	}

	render () {
		const { data } = this.props;
		return (
			<TouchableOpacity style={styles.paiziBox} onPress={() => { this._didPressShowStateLightBox(data.orderId, data.processInstanceId) }} activeOpacity={1}>
				<Image style={styles.paiziBg} source={require('../../../../../imgs/apply/topTitle.png')} />
				<View style={styles.paizi}>
					<Text style={styles.topLeft}>{data.auditResultName}</Text>
					<Text style={styles.topRight} numberOfLines={2}>{data.companyName}</Text>
				</View>
				<StateLightBox  {...this.stateLightBoxData} textStyle={{ marginLeft: 15 * scale, marginRight: 5 * scale }} />
				{/* <ProgressModal {...this.stateLightBoxData} /> */}
			</TouchableOpacity>
		)
	}
}
